package cn.yujiago.activiti.controller;

import cn.yujiago.activiti.constant.MessageConstant;
import cn.yujiago.activiti.dto.ResponseEntity;
import cn.yujiago.activiti.entity.User;
import cn.yujiago.activiti.service.UserService;
import cn.yujiago.activiti.util.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/user/login")
    @ResponseBody
    public ResponseEntity login(User user){
        return userService.login(user);
    }

    @GetMapping("/user/logout")
    @ResponseBody
    public String logout(){
        SessionUtils.set(null);
        return MessageConstant.OPT_SUCCESS;
    }
}
